package it.terry.bussola.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import android.content.res.AssetManager;
import android.os.Handler;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import it.terry.bussola.*;
import it.terry.bussola.hardware.SensorManagerSimulator;



public class BussTesting extends ActivityInstrumentationTestCase2<SimulationActivity>{
	
	private static final String LOC_TAG = "TESTING";
	private SimulationActivity myActivity;
	private List <String> data;
	@SuppressWarnings("unused")
	private SensorManagerSimulator mybuss;
	private Autocordsender mycord;
	private Handler handler;
	

	public BussTesting() {
		super("it.terry.bussola",SimulationActivity.class);
		// TODO Auto-generated constructor stub
	}

	@SuppressWarnings("static-access")
	@Override
	protected void setUp() throws Exception{
		super.setUp();
		
		setActivityInitialTouchMode(false);
		myActivity = getActivity();
		mybuss = SensorManagerSimulator.getSystemService(getInstrumentation().getContext(), getInstrumentation().getContext().SENSOR_SERVICE);
		handler = myActivity.handler;
		mycord = new Autocordsender(getInstrumentation().getContext(),handler);
		
	}
	public void testcase1(){
		
		int i = 0;
		AssetManager am = getInstrumentation().getContext().getAssets();
		//prelievo
		try {
		data = new ArrayList<String>();
		InputStream is = am.open("buss_cord.txt");
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		String line = null;
		while ((line = reader.readLine()) != null) {

			data.add(line);
		}
		Log.d(LOC_TAG, data.size() + " lines");
		Log.d(LOC_TAG, "Memorizzato"+data.toString());
      
		 	} catch (IOException e) {

		e.printStackTrace();
	}
		 	
		 	//USCITA
	        do{
	        	
	        
		 	for (String str: data) {
	        	
	            try {
					Thread.sleep(500);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	            
	            
	            // Setta la posizione
				String[] parts = str.split(",");
				Float x = Float.valueOf(parts[0]);
				Float y = Float.valueOf(parts[1]);
				Float z = Float.valueOf(parts[2]);
				i++;
				mycord.set_cordinate(x, y, z);
		 	}
		 	}while(i<30);
	}
	
}
